package edu.cmu.cs.cs214.hw9.client.gui;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import edu.cmu.cs.cs214.hw9.client.backend.NetworkDatabase;
import edu.cmu.cs.cs214.hw9.client.controllers.BackendCacheAdapter;
import edu.cmu.cs.cs214.hw9.client.controllers.FacelookController;

/**
 * Program state.
 */
public class Main {
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				// Initialize the database.
				BackendCacheAdapter backend = new BackendCacheAdapter(new NetworkDatabase());
				
				// Initialize the login/registration frame.
				JFrame frame = new JFrame("Facelook");
				FacelookScreen currentScreen = new LoginScreen();
				
				// Initialize a login controller to handle login/registration
				FacelookController controller = new FacelookController(backend, frame, currentScreen);
				currentScreen.registerController(controller);
				
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.add(currentScreen);
				frame.pack();
				frame.setResizable(false); // Prevent resizing so that we don't have to repack.
				
				frame.setVisible(true);
			}
		});
	}

}
